package com.andaily.domain.account;

import com.andaily.domain.shared.Repository;
import com.andaily.infrastructure.mybatis.data.AccountStatisticsData;
import org.apache.ibatis.annotations.Param;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * @author Shengzhao Li
 */
public interface AccountRepository extends Repository {

    Account findByGuid(String guid);

    void saveAccount(Account account);

    List<AccountType> findDefaultAccountTypes(@Param("logged") boolean logged);

    AccountType findAccountTypeByGuid(String guid);

    void updateAccountTypeUsedTimes(@Param("newTimes") int newTimes, @Param("guid") String guid);

    List<Account> findByPaginated(Map<String, Object> paramMap);

    void saveAccountType(AccountType accountType);

    int findTotalSizeByPaginated(Map<String, Object> paramMap);

    int totalAccountSize();

    void updateAccount(Account account);

    void archiveAccountByGuid(String guid);

    List<AccountType> findMyAccountTypes(String guid);

    void updateAccountType(AccountType type);

    void archiveAccountTypeByGuid(String guid);

    List<Account> findAccounts(Map<String, Object> params);

    int findTotalSize(Map<String, Object> params);

    BigDecimal findTotalAmount(Map<String, Object> params);

    List<Account> findArchivedAccounts(String guid);

    /**
     * Physical delete the Account data by guid.
     *
     * @param guid Account guid
     */
    void removeAccount(String guid);

    /**
     * It's mean: set the account <i>archived</i>  = false.
     *
     * @param guid Account guid
     */
    void activeAccount(String guid);

    /**
     * Find all Account total amount
     *
     * @return Total amount
     */
    BigDecimal findAllTotalAmount();

    List<AccountStatisticsData> findDailyStatistics(Map<String, Object> queryParams);

    int totalDailyAccountSize(Map<String, Object> queryParams);

    List<Account> findStatisticsAccounts(Map<String, Object> params);

    int totalStatisticsAccounts(Map<String, Object> params);

    List<AccountStatisticsData> findTypeStatistics(Map<String, Object> params);

    int totalTypeStatistics(Map<String, Object> params);

    List<AccountStatisticsData> findTypeChartData(@Param("userGuid") String userGuid, @Param("chartDataSize") int chartDataSize);

    List<AccountStatisticsData> findDailyChartData(@Param("userGuid") String userGuid, @Param("chartDataSize") int chartDataSize);

    AccountStatisticsData findIncomeStatisticsData(@Param("userGuid") String userGuid, @Param("incomeTypeGuid") String incomeTypeGuid);

    AccountStatisticsData findExpenditureStatisticsData(@Param("userGuid") String userGuid, @Param("incomeTypeGuid") String incomeTypeGuid);

    List<AccountStatisticsData> findMonthStatisticsData(Map<String, Object> params);

    int totalMonthStatisticsData(Map<String, Object> params);

    List<AccountStatisticsData> findMonthChartData(@Param("userGuid") String userGuid, @Param("chartDataSize") int chartDataSize);
}
